﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using UygulamaTakbisService.wsTakbisServis;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Diagnostics;

namespace UygulamaTakbisService
{
    public class IdariBirimDao : IDisposable
    {
        TAKBISWebService takbisServis = new TAKBISWebService();

        public bool IlBilgiKaydet(IlBilgi ilBilgi)
        {
            bool sonuc;
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TakbisBilgiSorguLogConnection"].ToString()))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    con.Open();
                    SqlTransaction transaction = con.BeginTransaction("trans");
                    try
                    {
                        cmd.CommandText = @"INSERT INTO IlBilgi with(updlock) (IlBilgiID,Ad,Aktifmi,KayitTarih) VALUES (@IlBilgiID,@Ad,@Aktifmi,Getdate())";

                        if (ilBilgi.IlBilgiID != null)
                            cmd.Parameters.Add("@IlBilgiID", ilBilgi.IlBilgiID);
                        else
                            cmd.Parameters.Add("@IlBilgiID", DBNull.Value);

                        if (ilBilgi.Ad != null)
                            cmd.Parameters.Add("@Ad", ilBilgi.Ad);
                        else
                            cmd.Parameters.Add("@Ad", DBNull.Value);

                        if (ilBilgi.Aktifmi != null)
                            cmd.Parameters.Add("@Aktifmi", (byte)ilBilgi.Aktifmi);
                        else
                            cmd.Parameters.Add("@Aktifmi", DBNull.Value);

                        cmd.Connection = con;
                        cmd.Transaction = transaction;
                        cmd.ExecuteScalar();
                        transaction.Commit();
                        sonuc = true;
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        sonuc = false;
                        using (ExceptionLogDao el = new ExceptionLogDao())
                        {
                            el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                        }
                    }
                    finally
                    {
                        con.Close();
                        con.Dispose();
                        cmd.Dispose();
                    }
                    return sonuc;
                }
            }
        }

        public bool IlBilgiKayitliMi(IlBilgi ilBilgi)
        {
            bool sonuc = false;
            try
            {
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TakbisBilgiSorguLogConnection"].ToString()))
                {
                    string sql = string.Format(@"SELECT * 
                                                 FROM IlBilgi with(nolock)
                                                 WHERE IlBilgiID = {0} and
                                                       Ad like '{1}' and
                                                       AktifMi = {2}", ilBilgi.IlBilgiID, ilBilgi.Ad, (byte)ilBilgi.Aktifmi);
                    using (SqlCommand cmd = new SqlCommand(sql))
                    {
                        using (SqlDataAdapter sda = new SqlDataAdapter())
                        {
                            cmd.Connection = con;
                            sda.SelectCommand = cmd;
                            cmd.CommandTimeout = 60000;
                            DataTable dt = new DataTable();
                            sda.Fill(dt);
                            if (dt.Rows.Count >= 1)
                                sonuc = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sonuc;
        }

        public bool IlceBilgiKaydet(IlceBilgi ilceBilgi)
        {
            bool sonuc;
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TakbisBilgiSorguLogConnection"].ToString()))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    con.Open();
                    SqlTransaction transaction = con.BeginTransaction("trans");
                    try
                    {
                        cmd.CommandText = @"INSERT INTO IlceBilgi with(updlock) (IlceBilgiID,Ad,IlBilgiID,AktifMi,KayitTarih) VALUES (@IlceBilgiID,@Ad,@IlBilgiID,@AktifMi,getdate())";

                        if (ilceBilgi.IlceBilgiID != null)
                            cmd.Parameters.Add("@IlceBilgiID", ilceBilgi.IlceBilgiID);
                        else
                            cmd.Parameters.Add("@IlceBilgiID", DBNull.Value);

                        if (ilceBilgi.Ad != null)
                            cmd.Parameters.Add("@Ad", ilceBilgi.Ad);
                        else
                            cmd.Parameters.Add("@Ad", DBNull.Value);

                        if (ilceBilgi.IlID != null)
                            cmd.Parameters.Add("@IlBilgiID", ilceBilgi.IlID);
                        else
                            cmd.Parameters.Add("@IlBilgiID", DBNull.Value);

                        if (ilceBilgi.Aktifmi != null)
                            cmd.Parameters.Add("@Aktifmi", (byte)ilceBilgi.Aktifmi);
                        else
                            cmd.Parameters.Add("@Aktifmi", DBNull.Value);

                        cmd.Connection = con;
                        cmd.Transaction = transaction;
                        cmd.ExecuteScalar();
                        transaction.Commit();
                        sonuc = true;
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        sonuc = false;
                        using (ExceptionLogDao el = new ExceptionLogDao())
                        {
                            el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                        }
                    }
                    finally
                    {
                        con.Close();
                        con.Dispose();
                        cmd.Dispose();
                    }
                    return sonuc;
                }
            }
        }

        public bool IlceBilgiKayitliMi(IlceBilgi ilceBilgi)
        {
            bool sonuc = false;
            try
            {
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TakbisBilgiSorguLogConnection"].ToString()))
                {
                    string sql = string.Format(@"SELECT * 
                                                 FROM IlceBilgi with(nolock) 
                                                 WHERE IlceBilgiID = {0} and 
                                                       Ad like '{1}' and
                                                       IlBilgiID = {2} and
                                                       AktifMi = {3}", ilceBilgi.IlceBilgiID, ilceBilgi.Ad, ilceBilgi.IlID, (byte)ilceBilgi.Aktifmi);
                    using (SqlCommand cmd = new SqlCommand(sql))
                    {
                        using (SqlDataAdapter sda = new SqlDataAdapter())
                        {
                            cmd.Connection = con;
                            sda.SelectCommand = cmd;
                            cmd.CommandTimeout = 60000;
                            DataTable dt = new DataTable();
                            sda.Fill(dt);
                            if (dt.Rows.Count >= 1)
                                sonuc = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sonuc;
        }

        public bool KurumBilgiKaydet(KurumBilgi kurumBilgi)
        {
            bool sonuc;
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TakbisBilgiSorguLogConnection"].ToString()))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    con.Open();
                    SqlTransaction transaction = con.BeginTransaction("trans");
                    try
                    {
                        cmd.CommandText = @"INSERT INTO KurumBilgi with(updlock) (KurumBilgiID,Ad,IlceBilgiID,AktifMi,KayitTarih) VALUES (@KurumBilgiID,@Ad,@IlceBilgiID,@AktifMi,getdate())";

                        if (kurumBilgi.KurumBilgiID != null)
                            cmd.Parameters.Add("@KurumBilgiID", kurumBilgi.KurumBilgiID);
                        else
                            cmd.Parameters.Add("@KurumBilgiID", DBNull.Value);

                        if (kurumBilgi.Ad != null)
                            cmd.Parameters.Add("@Ad", kurumBilgi.Ad);
                        else
                            cmd.Parameters.Add("@Ad", DBNull.Value);

                        if (kurumBilgi.IlceID != null)
                            cmd.Parameters.Add("@IlceBilgiID", kurumBilgi.IlceID);
                        else
                            cmd.Parameters.Add("@IlceBilgiID", DBNull.Value);

                        if (kurumBilgi.Aktifmi != null)
                            cmd.Parameters.Add("@Aktifmi", (byte)kurumBilgi.Aktifmi);
                        else
                            cmd.Parameters.Add("@Aktifmi", DBNull.Value);

                        cmd.Connection = con;
                        cmd.Transaction = transaction;
                        cmd.ExecuteScalar();
                        transaction.Commit();
                        sonuc = true;
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        sonuc = false;
                        using (ExceptionLogDao el = new ExceptionLogDao())
                        {
                            el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                        }
                    }
                    finally
                    {
                        con.Close();
                        con.Dispose();
                        cmd.Dispose();
                    }
                    return sonuc;
                }
            }
        }

        public bool KurumBilgiKayitliMi(KurumBilgi kurumBilgi)
        {
            bool sonuc = false;
            try
            {
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TakbisBilgiSorguLogConnection"].ToString()))
                {
                    string sql = string.Format(@"SELECT * 
                                                 FROM KurumBilgi with(nolock) 
                                                 WHERE KurumBilgiID = {0} and 
                                                       Ad like '{1}' and
                                                       IlceBilgiID = {2} and
                                                       AktifMi = {3}", kurumBilgi.KurumBilgiID, kurumBilgi.Ad, kurumBilgi.IlceID, (byte)kurumBilgi.Aktifmi);
                    using (SqlCommand cmd = new SqlCommand(sql))
                    {
                        using (SqlDataAdapter sda = new SqlDataAdapter())
                        {
                            cmd.Connection = con;
                            sda.SelectCommand = cmd;
                            cmd.CommandTimeout = 60000;
                            DataTable dt = new DataTable();
                            sda.Fill(dt);
                            if (dt.Rows.Count >= 1)
                                sonuc = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sonuc;
        }

        public bool MahalleBilgiKaydet(MahalleBilgi mahalleBilgi)
        {
            bool sonuc;
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TakbisBilgiSorguLogConnection"].ToString()))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    con.Open();
                    SqlTransaction transaction = con.BeginTransaction("trans");
                    try
                    {
                        cmd.CommandText = @"INSERT INTO MahalleBilgi with(updlock) (MahalleBilgiID,Ad,KurumBilgiID,AktifMi,KayitTarih) VALUES (@MahalleBilgiID,@Ad,@KurumBilgiID,@AktifMi,GETDATE())";

                        if (mahalleBilgi.MahalleBilgiID != null)
                            cmd.Parameters.Add("@MahalleBilgiID", mahalleBilgi.MahalleBilgiID);
                        else
                            cmd.Parameters.Add("@KurumBilgiID", DBNull.Value);

                        if (mahalleBilgi.Ad != null)
                            cmd.Parameters.Add("@Ad", mahalleBilgi.Ad);
                        else
                            cmd.Parameters.Add("@Ad", DBNull.Value);

                        if (mahalleBilgi.KurumID != null)
                            cmd.Parameters.Add("@KurumBilgiID", mahalleBilgi.KurumID);
                        else
                            cmd.Parameters.Add("@KurumBilgiID", DBNull.Value);

                        if (mahalleBilgi.Aktifmi != null)
                            cmd.Parameters.Add("@Aktifmi", (byte)mahalleBilgi.Aktifmi);
                        else
                            cmd.Parameters.Add("@Aktifmi", DBNull.Value);

                        cmd.Connection = con;
                        cmd.Transaction = transaction;
                        cmd.ExecuteScalar();
                        transaction.Commit();
                        sonuc = true;
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        sonuc = false;
                        using (ExceptionLogDao el = new ExceptionLogDao())
                        {
                            el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                        }
                    }
                    finally
                    {
                        con.Close();
                        con.Dispose();
                        cmd.Dispose();
                    }
                    return sonuc;
                }
            }
        }

        public bool MahalleBilgiKayitliMi(MahalleBilgi mahalleBilgi)
        {
            bool sonuc = false;
            try
            {
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TakbisBilgiSorguLogConnection"].ToString()))
                {
                    string sql = string.Format(@"SELECT * 
                                                 FROM MahalleBilgi with(nolock) 
                                                 WHERE MahalleBilgiID = {0} and
                                                       Ad like '{1}' and
                                                       KurumBilgiID = {2} and
                                                       AktifMi = {3}", mahalleBilgi.MahalleBilgiID, mahalleBilgi.Ad, mahalleBilgi.KurumID, (byte)mahalleBilgi.Aktifmi);
                    using (SqlCommand cmd = new SqlCommand(sql))
                    {
                        using (SqlDataAdapter sda = new SqlDataAdapter())
                        {
                            cmd.Connection = con;
                            sda.SelectCommand = cmd;
                            cmd.CommandTimeout = 60000;
                            DataTable dt = new DataTable();
                            sda.Fill(dt);
                            if (dt.Rows.Count >= 1)
                                sonuc = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sonuc;
        }

        public bool OrganizasyonBilgiKaydet(OrganizasyonBilgi organizasyonBilgi)
        {
            bool sonuc;
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TakbisBilgiSorguLogConnection"].ToString()))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    con.Open();
                    SqlTransaction transaction = con.BeginTransaction("trans");
                    try
                    {
                        cmd.CommandText = @"INSERT INTO OrganizasyonBilgi with(updlock) (OrganizasyonBilgiID,Ad,ResmiAd,KayitTarih) VALUES (@OrganizasyonBilgiID,@Ad,@ResmiAd,GETDATE())";

                        if (organizasyonBilgi.OrganizasyonBilgiID != null)
                            cmd.Parameters.Add("@OrganizasyonBilgiID", organizasyonBilgi.OrganizasyonBilgiID);
                        else
                            cmd.Parameters.Add("@OrganizasyonBilgiID", DBNull.Value);

                        if (organizasyonBilgi.Ad != null)
                            cmd.Parameters.Add("@Ad", organizasyonBilgi.Ad);
                        else
                            cmd.Parameters.Add("@Ad", DBNull.Value);

                        if (organizasyonBilgi.ResmiAd != null)
                            cmd.Parameters.Add("@ResmiAd", organizasyonBilgi.ResmiAd);
                        else
                            cmd.Parameters.Add("@ResmiAd", DBNull.Value);

                        cmd.Connection = con;
                        cmd.Transaction = transaction;
                        cmd.ExecuteScalar();
                        transaction.Commit();
                        sonuc = true;
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        sonuc = false;
                        using (ExceptionLogDao el = new ExceptionLogDao())
                        {
                            el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                        }
                    }
                    finally
                    {
                        con.Close();
                        con.Dispose();
                        cmd.Dispose();
                    }
                    return sonuc;
                }
            }
        }

        public bool OrganizasyonBilgiKayitliMi(OrganizasyonBilgi organizasyonBilgi)
        {
            bool sonuc = false;
            try
            {
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TakbisBilgiSorguLogConnection"].ToString()))
                {
                    string sql = string.Format(@"SELECT * 
                                                 FROM OrganizasyonBilgi with(nolock) 
                                                 WHERE OrganizasyonBilgiID = {0} and
                                                       Ad like '{1}' and
                                                       ResmiAd like '{2}'", organizasyonBilgi.OrganizasyonBilgiID, organizasyonBilgi.Ad, organizasyonBilgi.ResmiAd);
                    using (SqlCommand cmd = new SqlCommand(sql))
                    {
                        using (SqlDataAdapter sda = new SqlDataAdapter())
                        {
                            cmd.Connection = con;
                            sda.SelectCommand = cmd;
                            cmd.CommandTimeout = 60000;
                            DataTable dt = new DataTable();
                            sda.Fill(dt);
                            if (dt.Rows.Count >= 1)
                                sonuc = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sonuc;
        }

        public bool UlkeBilgiKaydet(UlkeBilgi ulkeBilgi)
        {
            bool sonuc;
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TakbisBilgiSorguLogConnection"].ToString()))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    con.Open();
                    SqlTransaction transaction = con.BeginTransaction("trans");
                    try
                    {
                        cmd.CommandText = @"INSERT INTO UlkeBilgi with(updlock) (UlkeBilgiID,Ad,ResmiAd,KayitTarih) VALUES (@UlkeBilgiID,@Ad,@ResmiAd,GetDate())";

                        if (ulkeBilgi.UlkeBilgiID != null)
                            cmd.Parameters.Add("@UlkeBilgiID", ulkeBilgi.UlkeBilgiID);
                        else
                            cmd.Parameters.Add("@UlkeBilgiID", DBNull.Value);

                        if (ulkeBilgi.Ad != null)
                            cmd.Parameters.Add("@Ad", ulkeBilgi.Ad);
                        else
                            cmd.Parameters.Add("@Ad", DBNull.Value);

                        if (ulkeBilgi.ResmiAd != null)
                            cmd.Parameters.Add("@ResmiAd", ulkeBilgi.ResmiAd);
                        else
                            cmd.Parameters.Add("@ResmiAd", DBNull.Value);

                        cmd.Connection = con;
                        cmd.Transaction = transaction;
                        cmd.ExecuteScalar();
                        transaction.Commit();
                        sonuc = true;
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        sonuc = false;
                        using (ExceptionLogDao el = new ExceptionLogDao())
                        {
                            el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                        }
                    }
                    finally
                    {
                        con.Close();
                        con.Dispose();
                        cmd.Dispose();
                    }
                    return sonuc;
                }
            }
        }

        public bool UlkeBilgiKayitliMi(UlkeBilgi UlkeBilgi)
        {
            bool sonuc = false;
            try
            {
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TakbisBilgiSorguLogConnection"].ToString()))
                {
                    string sql = string.Format(@"SELECT * 
                                                 FROM UlkeBilgi with(nolock) 
                                                 WHERE UlkeBilgiID = {0} and
                                                       Ad like '{1}' and
                                                       ResmiAd like '{2}'", UlkeBilgi.UlkeBilgiID, UlkeBilgi.Ad, UlkeBilgi.ResmiAd);
                    using (SqlCommand cmd = new SqlCommand(sql))
                    {
                        using (SqlDataAdapter sda = new SqlDataAdapter())
                        {
                            cmd.Connection = con;
                            sda.SelectCommand = cmd;
                            cmd.CommandTimeout = 60000;
                            DataTable dt = new DataTable();
                            sda.Fill(dt);
                            if (dt.Rows.Count >= 1)
                                sonuc = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sonuc;
        }

        public List<IlBilgi> GetirIlBilgiAdDan(string ilAd, long kullaniciID)
        {
            List<IlBilgi> ilBilgiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    ilBilgiList = takbisServis.GetirIlBilgiAdDan(ilAd).ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    foreach (IlBilgi ilBilgi in ilBilgiList)
                    {
                        if (!IlBilgiKayitliMi(ilBilgi))
                        {
                            bool ilBilgiKaydedildiMi = IlBilgiKaydet(ilBilgi);
                        }
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirIlBilgiAdDan", null, ilBilgiList, "İlAdı = " + ilAd, Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return ilBilgiList;
        }

        public List<IlBilgi> GetirIlBilgiTum(long kullaniciID)
        {
            List<IlBilgi> ilBilgiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    ilBilgiList = takbisServis.GetirIlBilgiTum().ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    foreach (IlBilgi ilBilgi in ilBilgiList)
                    {
                        if (!IlBilgiKayitliMi(ilBilgi))
                        {
                            bool ilBilgiKaydedildiMi = IlBilgiKaydet(ilBilgi);
                        }
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirIlBilgiTum", null, ilBilgiList, null, Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return ilBilgiList;
        }

        public IlBilgi GetirIlBilgiIDDen(decimal ilID, long kullaniciID)
        {
            IlBilgi ilBilgi = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    ilBilgi = takbisServis.GetirIlBilgiIDDen(ilID);
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    if (!IlBilgiKayitliMi(ilBilgi))
                    {
                        bool ilBilgiKaydedildiMi = IlBilgiKaydet(ilBilgi);
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirIlBilgiIDDen", null, ilBilgi, "İlID = " + ilID.ToString(), Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                    return ilBilgi;
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return ilBilgi;
        }

        public IlceBilgi GetirIlceBilgiIDDen(int ilceID, long kullaniciID)
        {
            IlceBilgi ilceBilgi = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    ilceBilgi = takbisServis.GetirIlceBilgiIDDen(ilceID);
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    if (!IlceBilgiKayitliMi(ilceBilgi))
                    {
                        bool ilceBilgiKaydedildiMi = IlceBilgiKaydet(ilceBilgi);
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirIlceBilgiIDDen", null, ilceBilgi, "İlçeID = " + ilceID.ToString(), Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return ilceBilgi;
        }

        public List<IlceBilgi> GetirIlceBilgiIlIDDen(decimal ilID, long kullaniciID)
        {
            List<IlceBilgi> ilceBilgiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    ilceBilgiList = takbisServis.GetirIlceBilgiIlIDDen(ilID).ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    foreach (IlceBilgi ilceBilgi in ilceBilgiList)
                    {
                        if (!IlceBilgiKayitliMi(ilceBilgi))
                        {
                            bool ilceBilgiKaydedildiMi = IlceBilgiKaydet(ilceBilgi);
                        }
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirIlceBilgiIlIDDen", null, ilceBilgiList, "İlID = " + ilID.ToString(), Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return ilceBilgiList;
        }

        public List<KurumBilgi> GetirKurumBilgiAdDan(string kurumAd, long kullaniciID)
        {
            List<KurumBilgi> kurumBilgiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    kurumBilgiList = takbisServis.GetirKurumBilgiAdDan(kurumAd).ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    foreach (KurumBilgi kurumBilgi in kurumBilgiList)
                    {
                        if (!KurumBilgiKayitliMi(kurumBilgi))
                        {
                            bool kurumBilgiKaydedildiMi = KurumBilgiKaydet(kurumBilgi);
                        }
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirKurumBilgiAdDan", null, kurumBilgiList, "KurumAdı = " + kurumAd, Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return kurumBilgiList;
        }

        public KurumBilgi GetirKurumBilgiIDDen(short kurumId, long kullaniciID)
        {
            KurumBilgi kurumBilgi = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    kurumBilgi = takbisServis.GetirKurumBilgiIDDen(kurumId);
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    if (!KurumBilgiKayitliMi(kurumBilgi))
                    {
                        bool kurumBilgiKaydedildiMi = KurumBilgiKaydet(kurumBilgi);
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirKurumBilgiIDDen", null, kurumBilgi, "KurumID = " + kurumId.ToString(), Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return kurumBilgi;
        }

        public List<KurumBilgi> GetirKurumBilgiIlceIDDen(decimal ilceID, long kullaniciID)
        {
            List<KurumBilgi> kurumBilgiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    kurumBilgiList = takbisServis.GetirKurumBilgiIlceIDDen(ilceID).ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    foreach (KurumBilgi kurumBilgi in kurumBilgiList)
                    {
                        if (!KurumBilgiKayitliMi(kurumBilgi))
                        {
                            bool kurumBilgiKaydedildiMi = KurumBilgiKaydet(kurumBilgi);
                        }
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirKurumBilgiIlceIDDen", null, kurumBilgiList, "İlçeID = " + ilceID, Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return kurumBilgiList;
        }

        public List<MahalleBilgi> GetirMahalleBilgiKurumIDDen(short kurumId, long kullaniciID)
        {
            List<MahalleBilgi> mahalleBilgiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    mahalleBilgiList = takbisServis.GetirMahalleBilgiKurumIDDen(kurumId).ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    foreach (MahalleBilgi mahalleBilgi in mahalleBilgiList)
                    {
                        if (!MahalleBilgiKayitliMi(mahalleBilgi))
                        {
                            bool mahalleBilgiKaydedildiMi = MahalleBilgiKaydet(mahalleBilgi);
                        }
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirMahalleBilgiKurumIDDen", null, mahalleBilgiList, "KurumID = " + kurumId.ToString(), Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return mahalleBilgiList;
        }

        public List<MahalleBilgi> GetirMahalleBilgiAdVeKurumIDDen(short kurumId, string mahalleAd, long kullaniciID)
        {
            List<MahalleBilgi> mahalleBilgiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    mahalleBilgiList = takbisServis.GetirMahalleBilgiAdVeKurumIDDen(mahalleAd, kurumId).ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    foreach (MahalleBilgi mahalleBilgi in mahalleBilgiList)
                    {
                        if (!MahalleBilgiKayitliMi(mahalleBilgi))
                        {
                            bool mahalleBilgiKaydedildiMi = MahalleBilgiKaydet(mahalleBilgi);
                        }
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirMahalleBilgiAdVeKurumIDDen", null, mahalleBilgiList, "KurumID = " + kurumId.ToString() + ", MahalleAdi = " + mahalleAd, Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return mahalleBilgiList;
        }

        public MahalleBilgi GetirMahalleBilgiIDDen(decimal mahalleID, long kullaniciID)
        {
            MahalleBilgi mahalleBilgi = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    mahalleBilgi = takbisServis.GetirMahalleBilgiIDDen(mahalleID);
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    if (!MahalleBilgiKayitliMi(mahalleBilgi))
                    {
                        bool mahalleBilgiKaydedildiMi = MahalleBilgiKaydet(mahalleBilgi);
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirMahalleBilgiIDDen", null, mahalleBilgi, "MahalleID = " + mahalleID.ToString(), Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return mahalleBilgi;
        }

        public List<UlkeBilgi> GetirUlkeBilgiTum(long kullaniciID)
        {
            List<UlkeBilgi> ulkeBilgiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    ulkeBilgiList = takbisServis.GetirUlkeBilgiTum().ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    foreach (UlkeBilgi ulkeBilgi in ulkeBilgiList)
                    {
                        if (!UlkeBilgiKayitliMi(ulkeBilgi))
                        {
                            bool ulkeBilgiKaydedildiMi = UlkeBilgiKaydet(ulkeBilgi);
                        }
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirUlkeBilgiTum", null, ulkeBilgiList, null, Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return ulkeBilgiList;
        }

        public UlkeBilgi GetirUlkeBilgiIDDen(short ulkeID, long kullaniciID)
        {
            UlkeBilgi ulkeBilgi = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    ulkeBilgi = takbisServis.GetirUlkeBilgiIDDen(ulkeID);
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    if (!UlkeBilgiKayitliMi(ulkeBilgi))
                    {
                        bool ulkeBilgiKaydedildiMi = UlkeBilgiKaydet(ulkeBilgi);
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirUlkeBilgiIDDen", null, ulkeBilgi, "ÜlkeID = " + ulkeID.ToString(), Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return ulkeBilgi;
        }

        public List<OrganizasyonBilgi> GetirOrganizasyonBilgiTum(long kullaniciID)
        {
            List<OrganizasyonBilgi> organizasyonBilgiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    organizasyonBilgiList = takbisServis.GetirOrganizasyonBilgiTum().ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    foreach (OrganizasyonBilgi organizasyonBilgi in organizasyonBilgiList)
                    {
                        if (!OrganizasyonBilgiKayitliMi(organizasyonBilgi))
                        {
                            bool organizasyonBilgiKaydedildiMi = OrganizasyonBilgiKaydet(organizasyonBilgi);
                        }
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirOrganizasyonBilgiTum", null, organizasyonBilgiList, null, Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return organizasyonBilgiList;
        }

        public OrganizasyonBilgi GetirOrganizasyonBilgiIDDen(short organizasyonID, long kullaniciID)
        {
            OrganizasyonBilgi organizasyonBilgi = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    organizasyonBilgi = takbisServis.GetirOrganizasyonBilgiIDDen(organizasyonID);
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    if (!OrganizasyonBilgiKayitliMi(organizasyonBilgi))
                    {
                        bool organizasyonBilgiKaydedildiMi = OrganizasyonBilgiKaydet(organizasyonBilgi);
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirOrganizasyonBilgiIDDen", null, organizasyonBilgi, "OrganizasyonID = " + organizasyonID, Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return organizasyonBilgi;
        }

        public void Dispose()
        {
        }
    }
}
